package com.geo.geotool.service.tiff;

import org.geotools.coverage.grid.GridCoverage2D;
import org.geotools.data.DataStore;
import org.geotools.gce.geotiff.GeoTiffWriter;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import java.io.File;

/**
 * @Description: GeoTiff文件管理类
 * @Author: 逃离地球
 */
@Component
public class GeoTiffManager {
    @Autowired
    DataStore dataStore;
    /**
     * 保存GeoTiff文件
     * @param coverage  栅格数据
     * @param savePath 保存路径
     * @return
     */
    public boolean saveGeoTiff(GridCoverage2D coverage , String savePath){
        boolean isOk = true;
        // 保存tiff文件
        File outputFile = new File(savePath);
        try {
            GeoTiffWriter writer = new GeoTiffWriter(outputFile);
            writer.write(coverage, null);
            writer.dispose();
        }catch (Exception e){
            isOk = false;
        }
        return isOk;
    }
}
